import React, { useState, useEffect } from 'react';

const CountdownTimer = ({ seconds, onComplete }) => {
    const [timeLeft, setTimeLeft] = useState(seconds);

    useEffect(() => {
        let intervalId = null;
        if (timeLeft > 0) {
            intervalId = setInterval(() => {
                setTimeLeft(timeLeft - 1);
            }, 1000);
        }
        if (timeLeft === 0) {
            onComplete();
            clearInterval(intervalId);
        }
        return () => clearInterval(intervalId);
    }, [timeLeft, onComplete]);

    return (
        <div>
            {timeLeft}
        </div>
    );
};
export default CountdownTimer